package com.example.administrator.School;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.example.administrator.School.common.result.Result;
import com.example.administrator.School.until.BaseDetailActivity;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 值日表
 */
public class YingyongActivity extends BaseDetailActivity<Map> {
    @BindView(R.id.yingyong_gridview)
    GridView yingyong_gridview;

    private List<Map<String, Object>> dataList;
    private SimpleAdapter adapter;

    @BindView(R.id.quanbu)
    TextView quanbu;
    @BindView(R.id.moshiqiehuan)
    TextView moshi;
    @BindView(R.id.genghuanbeijing)
    TextView genghuanbeijing;



    //页面传值回调
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

    }

    @Override
    protected int getContentView() {
        return R.layout.dialog_yingyong_layout;
    }

    @Override
    protected void initData() {
        super.initData();
        //初始化数据
        initDatas();
        String[] from={"img","text"};
        int[] to={R.id.img,R.id.text};
        adapter=new SimpleAdapter(this, dataList, R.layout.yingyong_gridview_item, from, to);
        yingyong_gridview.setAdapter(adapter);
        yingyong_gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                AlertDialog.Builder builder= new AlertDialog.Builder(YingyongActivity.this);
                //点击事件
                if("班级信息".equals(dataList.get(arg2).get("text").toString())){
                    //班级信息，进入班级
                    startActivity(new Intent(YingyongActivity.this, DetailActivity.class));
                    finish();
                }else if("班级相册".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, PhotoActivity.class));
                    finish();
                }else if("班级活动".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, HuoDongActivity.class));
                    finish();
                }else if("课程表".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, KcbActivity.class));
                    finish();
                }else if("考勤记录".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, KaoQinActivity.class));
                    finish();
                }else if("班级值日".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this,
                            DutyActivity.class));
                    finish();
                }else if("通知".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, TongZhiActivity.class));
                    finish();
                }else if("表扬栏".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, PhotoActivity.class));
                    finish();
                }else if("设置".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, PhotoActivity.class));
                    finish();
                }else if("个人中心".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, MyActivity.class));
                    finish();
                }
            }
        });
    }

    //    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.dialog_yingyong_layout);
//        yingyong_gridview = (GridView) findViewById(R.id.yingyong_gridview);
//
//    }
    //初始化应用全部
    void initDatas() {
        //图标
        int[] icno = {R.drawable.banji, R.drawable.xiangce, R.drawable.huodong,
                R.drawable.kcb, R.drawable.kaoqin, R.drawable.zhiri, R.drawable.touxiang,
                R.drawable.biaoyang, R.drawable.setting, R.drawable.my};
        //图标下的文字
        String[] name = {"班级信息", "班级相册", "班级活动", "课程表", "考勤记录", "班级值日", "通知", "表扬栏", "设置", "个人中心"};
        dataList = new ArrayList<Map<String, Object>>();
        for (int i = 0; i <icno.length; i++) {
            Map<String, Object> map=new HashMap<String, Object>();
            map.put("img", icno[i]);
            map.put("text",name[i]);
            dataList.add(map);
        }
    }


    //初始化模式切换
    void initMsqh() {
        //图标
        int[] icno = {R.drawable.banji, R.drawable.xiangce, R.drawable.huodong,
                R.drawable.kcb, R.drawable.kaoqin, R.drawable.zhiri};
        //图标下的文字
        String[] name = {"常规模式", "考试模式", "欢迎模式", "上课模式", "自定义模式", "通知模式"};
        dataList = new ArrayList<Map<String, Object>>();
        for (int i = 0; i <icno.length; i++) {
            Map<String, Object> map=new HashMap<String, Object>();
            map.put("img", icno[i]);
            map.put("text",name[i]);
            dataList.add(map);
        }
    }

    //点击全部应用
    @OnClick({R.id.quanbu})
    void quanbu(){
        quanbu.setBackgroundResource(R.drawable.yingyong);
        moshi.setBackgroundResource(R.drawable.yingyong1);
        genghuanbeijing.setBackgroundResource(R.drawable.yingyong1);
        yingyong_gridview = (GridView) findViewById(R.id.yingyong_gridview);
        dataList.clear();
        adapter.notifyDataSetChanged();
        //初始化数据
        initDatas();
        String[] from={"img","text"};
        int[] to={R.id.img,R.id.text};
        adapter=new SimpleAdapter(this, dataList, R.layout.yingyong_gridview_item, from, to);
        yingyong_gridview.setNumColumns(5);
        yingyong_gridview.setAdapter(adapter);
        yingyong_gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                AlertDialog.Builder builder= new AlertDialog.Builder(YingyongActivity.this);
                //点击事件
                if("班级信息".equals(dataList.get(arg2).get("text").toString())){
                    //班级信息，进入班级
                    startActivity(new Intent(YingyongActivity.this, DetailActivity.class));
                    finish();
                }else if("班级相册".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, PhotoActivity.class));
                    finish();
                }else if("班级活动".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, HuoDongActivity.class));
                    finish();
                }else if("课程表".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, KcbActivity.class));
                    finish();
                }else if("考勤记录".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, KaoQinActivity.class));
                    finish();
                }else if("班级值日".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this,
                            DutyActivity.class));
                    finish();
                }else if("通知".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, TongZhiActivity.class));
                    finish();
                }else if("表扬栏".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, PhotoActivity.class));
                    finish();
                }else if("设置".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, PhotoActivity.class));
                    finish();
                }else if("个人中心".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, MyActivity.class));
                    finish();
                }
            }
        });
    }

    //点击模式切换
    @OnClick(R.id.moshiqiehuan)
    void moshiqiehuan(){
        quanbu.setBackgroundResource(R.drawable.yingyong1);
        moshi.setBackgroundResource(R.drawable.yingyong);
        genghuanbeijing.setBackgroundResource(R.drawable.yingyong1);
        //初始化数据
        dataList.clear();
        adapter.notifyDataSetChanged();
        initMsqh();
        String[] from={"img","text"};
        int[] to={R.id.img,R.id.text};
        adapter=new SimpleAdapter(this, dataList, R.layout.yingyong_gridview_item, from, to);
        yingyong_gridview.setNumColumns(3);
        yingyong_gridview.setColumnWidth(120);
        yingyong_gridview.setAdapter(adapter);
        yingyong_gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                AlertDialog.Builder builder= new AlertDialog.Builder(YingyongActivity.this);
                //点击事件
                if("班级信息".equals(dataList.get(arg2).get("text").toString())){
                    //班级信息，进入班级
                    startActivity(new Intent(YingyongActivity.this, DetailActivity.class));
                    finish();
                }else if("班级相册".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, PhotoActivity.class));
                    finish();
                }
            }
        });
    }

    //点击更改背景
    @OnClick(R.id.genghuanbeijing)
    void genghuanbeijing(){
        quanbu.setBackgroundResource(R.drawable.yingyong1);
        moshi.setBackgroundResource(R.drawable.yingyong1);
        genghuanbeijing.setBackgroundResource(R.drawable.yingyong);
        //初始化数据
        dataList.clear();
        adapter.notifyDataSetChanged();
        initGgbj();
        String[] from={"img","text"};
        int[] to={R.id.img,R.id.text};
        adapter=new SimpleAdapter(this, dataList, R.layout.yingyong_gridview_item, from, to);
        yingyong_gridview.setNumColumns(3);
        yingyong_gridview.setColumnWidth(120);
        yingyong_gridview.setAdapter(adapter);
        yingyong_gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                AlertDialog.Builder builder= new AlertDialog.Builder(YingyongActivity.this);
                //点击事件
                if("活力".equals(dataList.get(arg2).get("text").toString())){
                    //班级信息，进入班级
                    startActivity(new Intent(YingyongActivity.this, DetailActivity.class));
                    finish();
                }else if("趣味".equals(dataList.get(arg2).get("text").toString())){
                    startActivity(new Intent(YingyongActivity.this, PhotoActivity.class));
                    finish();
                }
            }
        });
    }

    void  initGgbj(){
        //图标
        int[] icno = {R.drawable.banji, R.drawable.xiangce, R.drawable.huodong,
                R.drawable.kcb};
        //图标下的文字
        String[] name = {"活力", "趣味", "规范", "清新"};
        dataList = new ArrayList<Map<String, Object>>();
        for (int i = 0; i <icno.length; i++) {
            Map<String, Object> map=new HashMap<String, Object>();
            map.put("img", icno[i]);
            map.put("text",name[i]);
            dataList.add(map);
        }
    }

    @Override
    protected Type getType() {
        return null;
    }

    @Override
    protected void setData(Result<Map> result) {

    }

    @OnClick(R.id.close)
    void close(){
        finish();
    }
}

